﻿<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Pragma" content="no-cache">
<link rel="STYLESHEET" type="text/css" id="SkinStyleSheet">
<title>一键排版</title>
<style type="text/css">
td{
	padding:5px
}
</style>
<script language="javascript" type="text/javascript" src="../script/windialog.js"></script>
<script language="javascript" type="text/javascript">

window.onload=function()
{
	EditorWindow.renderWindowAsIE(window);

	var sel0=new EditorWindow._HTMLselect("selunitlineHeight",document);
	var sel1=new EditorWindow._HTMLselect("selunitpMarginBottom",document);
	var Options = new Array(
		new Array("%", "%"), 
		new Array("px", "px"),
		new Array("em", "em")
	);
	sel0.addOptions(Options);
	
	Options = new Array(
		new Array("px", "px"),
		new Array("em", "em")
	);
	
	sel1.addOptions(Options);
	sel1=new EditorWindow._HTMLselect("selunitpMarginTop",document);
	sel1.addOptions(Options);
	sel0=null;
	sel1=null;
	AutoResizeDialogWindow();
}

function __btnOk_onclick()
{
	__contentformat();
	window.close();
}


function __btnCancel_onclick()
{
	window.close();
}

function __contentformat()
{
	var d0,d1,d2,d3,__innerHTML;
	var __lineHeight=document.getElementById("input_lineHeight").value;
	var __lineHeightUnit=document.getElementById("selunitlineHeight").value;
	
	var __pmarginTop=document.getElementById("input_marginTop").value;
	var __pmarginUnitTop=document.getElementById("selunitpMarginTop").value;

	
	var __pmarginBottom=document.getElementById("input_marginBottom").value;
	var __pmarginUnitBottom=document.getElementById("selunitpMarginBottom").value;

	d0=document.getElementById("r0").checked;
	d1=document.getElementById("r1").checked;
	d2=document.getElementById("r2").checked;
	d3=document.getElementById("r3").checked;

	if (d0)
	{
		__innerHTML=XEditor.document.body.innerHTML;
		__innerHTML=__innerHTML.replace(new RegExp("\<BR\>", "gi"), "\<P\>");
		XEditor.document.body.innerHTML=__innerHTML;
		__innerHTML=XEditor.document.body.innerHTML;
		__innerHTML=__innerHTML.replace(new RegExp("\<P\>", "gi"), "\<\/P><P\>");
		XEditor.document.body.innerHTML=__innerHTML;

	}

	var i,elems;
	if (d3)
	{
		elems=XEditor.document.links;
		for (i=0;i<elems.length;i++)
		{
			if(!(elems[i].href.toString().indexOf(location.hostname)>0))
			{
				
				elems[i].removeNode();
			}
		}
		elems=null;
	}

	elems=XEditor.document.getElementsByTagName("p");
	for (i=0;i<elems.length;i++)
	{
		if (d1)
		{
			elems[i].style.textIndent="2em";		//首行缩进
		}
		if(d2)
		{
			if (elems[i].style.textAlign=="left" || elems[i].style.textAlign=="")
			{
				//设置2端对齐
				elems[i].style.textAlign="justify";
				elems[i].style.textJustify="inter-ideograph";
			}
		}
		if(__lineHeight)
			elems[i].style.lineHeight=__lineHeight+__lineHeightUnit;		//行距
		if(__pmarginBottom)
		{
			elems[i].style.marginBottom=__pmarginBottom+__pmarginUnitBottom;
		}
		if(__pmarginTop)
		{
			elems[i].style.marginTop=__pmarginTop+__pmarginUnitTop;
		}

	}
	elems=null;
	alert("排版完成");
}
</script>
</head>
<body class="dialog">
<!--<script language="javascript" type="text/javascript">dialogTitle("一键排版");</script>-->
<div class="dialogtitle">一键排版</div>

<fieldset><legend>文本设置</legend>
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><input type="checkbox" id="r0">&lt;BR&gt;替换成&lt;P&gt;</td>
    <td><input type="checkbox" id="r2">文字两端对齐</td>
    <td><input type="checkbox" id="r1">首行缩进两字符</td>
    <td><input type="checkbox" id="r3">去除非本域超链接</td>
  </tr>
  <tr>
    <td>文字行距<input type="text" id="input_lineHeight" value="" style="width: 45px" datatype="number"><select id="selunitlineHeight"></select></td>
    <td>
    	段落上距离<input type="text" id="input_marginTop" value="" style="width: 45px" datatype="number"><select id="selunitpMarginTop"></select>
    	</td>
    <td>段落下距离<input type="text" id="input_marginBottom" value="" style="width: 45px" datatype="number"><select id="selunitpMarginBottom" name="D1"></select></td>
    <td></td>
  </tr>
</table>
</fieldset>
<div class="buttons">
	<hr size="1" color="#B3AC9D">
	<script language="javascript" type="text/javascript">
		PrintButtons2();
	</script>
</div>

</body>

</html>
